package com.example.demo.nettydemo.common;

import com.example.demo.nettydemo.Message;
import com.example.demo.nettydemo.message.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CommandConstant {

    public final static Byte singleMessageRequest = 1;
    public final static Byte singleMessageResponse= 2;

    public final static Byte groupMessageRequest = 3;
    public final static Byte getGroupMessageResponse = 4;

    public final static Byte loginRequest = 5;
    public final static Byte loginResponse = 6;

    public static Map<Byte,Class<? extends Message>> messageTypeMap = new ConcurrentHashMap<>();

    static {
        messageTypeMap.put(singleMessageRequest, SingleMessageRequest.class);
        messageTypeMap.put(singleMessageResponse, SingleMessageResponse.class);

        messageTypeMap.put(groupMessageRequest, GroupMessageRequest.class);
        messageTypeMap.put(getGroupMessageResponse, GroupMessageResponse.class);

        messageTypeMap.put(loginRequest, LoginRequest.class);
        messageTypeMap.put(loginResponse,LoginResponse.class);
    }

    public static Class<? extends Message> getMessageClass(Byte messageType){
        return messageTypeMap.get(messageType);
    }


}
